<?php
/**
 * 用户管理
 * @copyright (c) Seer All Rights Reserved
 */

require_once 'globals.php';

$Users_Model = new Users_Model();
$action = $_POST['action'];
$tel = isset($_REQUEST['tel']) ? $_REQUEST['tel'] : '';

//显示在线报名用户(用户一览表检索)
if ($action == '' ) {
	$page = $_GET['pid'] ? $_GET['pid'] : '1';
	$sqlSegment .= ' ORDER BY buildtime DESC ';
	$pwd = '用户选择';
	$addUrl = $tel ? "tel={$tel}&" : '';
	$usersNum = $Users_Model->getUsersNum($tel);
	$users = $Users_Model->getUsersForAdmin($sqlSegment, $page, $tel);
	$pageurl =  pagination($usersNum, Option::get('admin_perpage_num'), $page, "user_list.php?{$addUrl}pid=");
	include View::getView('header');
	require_once View::getView('user/user_list');
	include View::getView('footer');View::output();
}

// 用户删除
if ($action == 'delete' ) {
	$users = isset($_POST['ids']) ? $_POST['ids'] : array();
	foreach ($users as $val)
	{
		$Users_Model->deleteUser($val);
	}
	seerDirect("./user_list.php?active_del=1");
}

// 用户编辑
if ($action == 'update') {
	$mode = $_POST['mode'];
	$wx_openid = $_POST['wx_openid'];

	// 编辑画面初期化
	if(!$mode)
	{
		$user=$Users_Model->getOneUserForUpdate($wx_openid);
		include View::getView('header');
		require_once View::getView('user/user_update');
		include View::getView('footer');
		View::output();
	}
	// 编辑信息提交
	else if($mode=="commit")
	{
		echo($action);
		echo($mode);
		$name = $_POST['name'];
		$tel = $_POST['tel'];
		$updateUser = array(
			'openid' => $wx_openid,
			'name' => $name,
			'tel' => $tel,
		);
		var_dump($updateUser);
		$Users_Model->updateUser($updateUser);
		seerDirect("./user_list.php?tel=".$tel."&active_update=1");
	}
}